import java.util.Scanner;

public class NGuessNumber {

    public static boolean isInArr(int random,int[] arr){
        for(int temp : arr){
            if(random == temp){
                return true;
            }
        }
        return false;
    }

    public static int[] generateAnswer(){
        int[] arr = new int[4];
        for(int temp : arr){
            temp = -1;
        }
        int index = 0;
        do {
            int random = (int) (Math.random() * 9);
            if (!isInArr(random, arr)) {
                arr[index] = random;
                index++;
            }
        } while (index != 4);
        return arr;
    }

    public static int[] getPlayerInput(){
        Scanner scanner = new Scanner(System.in);
        int[] arr = new int[4];
        for(int temp = 0;temp < arr.length;temp++){
            arr[temp] = scanner.nextInt();
        }
        return arr;
    }

    public static char[] compareGuessAnswer(int[] input,int[] answer){
        char[] chars = new char[4];
        for(int temp = 0;temp < 4;temp++){
            if(input[temp] != answer[temp]){
                chars[temp] = 'B';
            }else{
                chars[temp] = 'A';
            }
        }
        return chars;
    }

    public static boolean isWin(char[] chars){
        int count = 0;
        for(char temp : chars){
            if(temp == 'A'){
                count++;
            }
        }
        if(count >= 3){
            return true;
        }else{
            return false;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while(true) {
            System.out.println("是否开始游戏(是/否)");
            String is = scanner.next();
            boolean isWin = false;
            if(is.equals("否")){
                break;
            }else if(!is.equals("是")){
                System.out.println("请勿输入是/否以外的字符");
                continue;
            }
            int[] answer = generateAnswer();
            for(int temp = 0;temp < 10;temp++){
                System.out.println("你还有"+(10-temp)+"次机会");
                int[] input = getPlayerInput();
                if(isWin(compareGuessAnswer(input,answer))){
                    System.out.println("你赢了");
                }else{
                    if(temp < 9){
                        System.out.println("你输了,再试一次吧");
                    }else{
                        System.out.println("你输了，没有机会了");
                    }
                }
            }
        }


    }
}
